<template>
  <div class="status-panel">
    <div class="panel-title">
      <span class="panel-title-main">概览实时状态</span>
      <a class="detail-link" href="#" @click.prevent="showDetail">详细信息&gt;</a>
    </div>
    <div class="panel-content">
      <!-- 左侧 -->
      <div class="panel-left">
        <div v-for="item in leftList" :key="item.name" class="panel-row">
          <div class="row-main">
            <span class="row-title">{{ item.name }}</span>
            <span v-if="item.detail" class="row-detail">{{ item.detail }}</span>
          </div>
          <span class="status-dot"></span>
        </div>
      </div>
      <!-- 右侧 -->
      <div class="panel-right">
        <div v-for="item in rightList" :key="item.name" class="panel-row">
          <div class="row-main">
            <span class="row-title right-title">{{ item.name }}</span>
            <span v-if="item.detail" class="row-detail">{{ item.detail }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import axios from '../utils/axios'
import { useRouter } from 'vue-router'
const router = useRouter()

const leftList = ref<{ name: string; detail: string }[]>([])
const rightList = ref<{ name: string; detail: string }[]>([])

onMounted(() => {
  axios
    .get('/api/leftList')
    .then((res) => {
      if (Array.isArray(res.data)) {
        leftList.value = res.data.map((item) => ({
          name: item.name || '',
          detail: item.detail || ''
        }))
      }
    })
    .catch((err) => {
      console.error('获取数据失败:', err)
    })

  axios
    .get('/api/rightList')
    .then((res) => {
      if (Array.isArray(res.data)) {
        rightList.value = res.data.map((item) => ({
          name: item.name || '',
          detail: item.detail || ''
        }))
      }
    })
    .catch((err) => {
      console.error('获取数据失败:', err)
    })
})
const showDetail = (): void => {
  router.push('/detail')
}
</script>

<style scoped>
.status-panel {
  background: #fff;
  margin: 0;
  border-radius: 0 0 8px 8px;
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px #f0f1f2;
}
.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f3f4f7;
  border-bottom: 1.5px solid #e5e5e5;
  padding: 0 24px;
  height: 48px;
}
.panel-title-main {
  color: #2b4a6f;
  font-weight: bold;
  font-size: 18px;
  border-left: 4px solid #2b4a6f;
  padding-left: 12px;
}
.detail-link {
  color: #2b4a6f;
  font-size: 14px;
  text-decoration: none;
}
.panel-content {
  display: flex;
  flex: 1;
  overflow: auto;
  padding: 0 16px 16px 16px;
  gap: 16px;
}

.panel-left,
.panel-right {
  flex: 1;
  overflow-y: auto;
  background: #fff;
}
.panel-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  border-bottom: 1px solid #f0f0f0;
  padding: 0 8px;
}
.row-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 1;
}
.row-title {
  font-weight: normal;
  color: #222;
  font-size: 16px;
  margin-bottom: 2px;
}
.right-title {
  color: #2b4a6f;
}
.row-detail {
  color: #888;
  font-size: 13px;
  margin-bottom: 2px;
  margin-top: 2px;
  word-break: break-all;
}
.status-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f8f8f8;
  border: 1.5px solid #d0d0d0;
  margin-left: 12px;
}
</style>
